#include <iostream>
#include <string>
#include <queue>
using namespace std;

struct Node {
	string val;
	Node* left = nullptr;
	Node* right = nullptr;
};
string sp;
Node* T = nullptr;
void getTree(Node*& h)
{
	string cur;
	cin >> cur;
	if (cur == sp) return;
	h = new Node;
	h->val = cur;
	getTree(h->left);
	getTree(h->right);
}

int height(Node* h)
{
	if (!h) return 0;
	int l = height(h->left);
	int r = height(h->right);
	return 1 + max(l, r);
}

int main()
{
	cin >> sp;
	getTree(T);
	cout << height(T);
	return 0;
}
